/* 
 * File:   newmain.cpp
 * Author: spledger
 *
 * Created on December 18, 2008, 2:40 AM
 */
#include <stdio.h>
#include <stdlib.h>
#include "medialin.hpp"
#include <gst/gst.h>

using namespace std;
int main (int argc, char *argv[])
{
    const SDL_VideoInfo * info=NULL;

    printf("Initializing SDL...  Please Wait...\n");
    if(SDL_Init(SDL_INIT_EVERYTHING|SDL_INIT_EVENTTHREAD)==-1){
        printf("Couldn't initialize SDL.  Exiting now.  Error is below.\n\n");
        printf(SDL_GetError());
        exit(-1);
    }
    printf("SDL Initialized.\n");
    SDL_Surface * screen = NULL;
    atexit(SDL_Quit);
    //Initialize OpenGL stuff
    info=SDL_GetVideoInfo();
    
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);


    screen=SDL_SetVideoMode(1024,768,32,SDL_SWSURFACE|SDL_ANYFORMAT|SDL_OPENGL);
    if( screen == NULL){
        printf("Couldn't initialize video.  Exiting now.  Error is below.\n\n");
        printf(SDL_GetError());
        printf("\n");
        exit(1);
    }

    // initialize gstreamer.
    const gchar *nano_str;
    guint major, minor, micro, nano;
    gst_init(&argc,&argv);

    gst_version (&major, &minor, &micro, &nano);
    if (nano == 1)
        nano_str = "(CVS)";
    else if (nano == 2)
        nano_str = "(Prerelease)";
    else
        nano_str = "";

    printf ("This program is linked against GStreamer %d.%d.%d %s\n",
          major, minor, micro, nano_str);


    MediaLin ml=MediaLin();
    //MediaLin::setup_opengl(1024,768);
    int i=1;
    
    SDL_ShowCursor(SDL_ENABLE);
    
    while(ml.wasError()==0){
        screen=ml.drawScreen(screen);
        
        ml.doUpdate();
    }

    




    printf("Quitting SDL.\n");
    SDL_Quit();

    printf("Quitting program...\n");
    return 0;
}
